﻿import { Component, Injector, ViewChild, ViewEncapsulation, AfterViewInit } from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { PipelineServiceProxy, PipelineListDto,  PipelineNumDto } from '@shared/service-proxies/service-proxies';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent, MenuItem } from 'primeng/primeng';
import { BatchIntoStepComponent } from './batch-into-step.component';
import { BatchIntoReportComponent } from './batch-into-report.component';
import { Table } from 'primeng/table';
@Component({
  templateUrl: './step.component.html',
  styleUrls: ['./step.component.less'],
  encapsulation: ViewEncapsulation.None,
  animations: [appModuleAnimation()]
})

export class StepsComponent extends AppComponentBase implements AfterViewInit {
 @ViewChild('dataTable') dataTable: Table;
  @ViewChild('paginator') paginator: Paginator;
  @ViewChild('batchIntoStepModal') batchIntoStepModal: BatchIntoStepComponent;
  @ViewChild('batchIntoReportModal') batchIntoReportModal: BatchIntoReportComponent;

  filterText = '';
  data: any[];
  items: MenuItem[];
  status: '';
  type = 1;
  className1 = "active";
  className2 = "";
  className3 = "";
  num = new PipelineNumDto();
  constructor(
    injector: Injector,

    private _pipelineService: PipelineServiceProxy,
  ) {
    super(injector);
  }

  ngAfterViewInit(): void {
    this.getPipes();
    this._pipelineService.getNum().subscribe(result => {
      this.num = result;
  });

  }

  getPipes(event?: LazyLoadEvent) {
    if (this.primengTableHelper.shouldResetPaging(event)) {
      this.paginator.changePage(0);
      return;
    }

    this.primengTableHelper.showLoadingIndicator();

    this._pipelineService.getPipelines(
      this.filterText,
      this.type,
      '58',
      undefined,
      this.status,
     '',
      this.primengTableHelper.getMaxResultCount(this.paginator, event),
      this.primengTableHelper.getSkipCount(this.paginator, event),

    )
      .subscribe(result => {
        this.primengTableHelper.totalRecordsCount = result.totalCount;
        this.primengTableHelper.records = result.items;
     console.log(this.type)
        this.primengTableHelper.hideLoadingIndicator();


        //console.log(this.primengTableHelper.records);

      });
  }

  pipelineRun(pipe: PipelineListDto) {
    this._pipelineService.getPipelineAndRun(pipe.id)
      .subscribe(result => {
        this.notify.info('运行成功');
        this.getPipes();
      });
  }
  tabTypeClick(tab: number)
  {
      this.type = tab;
      if(tab==1)
      {
          this.className1="active";
          this.className2="";
          this.className3="";
      }
      else if(tab==2)
      {
          this.className1="";
          this.className2="active";
          this.className3="";
      }
      else if(tab==3)
      {
          this.className1="";
          this.className2="";
          this.className3="active";
      }
      this.getPipes();
  }
}
